package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Setmeal;
import com.itheima.reggie.service.ISetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/setmeal")
public class SetmealController {

    @Autowired
    private ISetmealService setmealService;

    // 套餐分页查询
    @GetMapping("/page")
    public ResultInfo findByPage(
            String name,
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {// 1.接收参数
        // 2.调用service查询
        Page<Setmeal> page = setmealService.findByPage(pageNum, pageSize, name);

        // 3.返回结果
        return ResultInfo.success(page);
    }

    // 套餐新增
    @PostMapping()
    public ResultInfo save(@RequestBody Setmeal setmeal) { // 1.接收参数
        // 2.调用service
        setmealService.save(setmeal);

        // 3.返回结果
        return ResultInfo.success(null);

    }

    //setmeal状态更新
    @PostMapping("/status/{status}")
    public ResultInfo updateStatus(@PathVariable Integer status,@RequestParam List<Long> ids){
        setmealService.updateStatus(status,ids);
        return ResultInfo.success(null);
    }


    // dish回显
    @GetMapping("/{id}") // 前面没有#
    public ResultInfo findById(@PathVariable Long id) { // 1.接收菜品id
        // 2.调用service查询
        Setmeal setmeal = setmealService.findById(id);
        // 3.返回结果
        return ResultInfo.success(setmeal);
    }

    // setmeal修改
    @PutMapping("")
    public ResultInfo update(@RequestBody Setmeal setmeal) { // 1.接收请求体参数
        // 2.调用service修改
        setmealService.updateSetmeal(setmeal);
        // 3.返回成功消息
        return ResultInfo.success(null);

    }

}
